package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="vote_item")
public class VoteItem extends BaseObject {
	@OneToMany(mappedBy = "voteItem", cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Answer.class)
	public Set<Answer> getAnsweres() {
		return answeres;
	}

	public void setAnsweres(Set<Answer> answeres) {
		this.answeres = answeres;
	}

	@Override
	public String toString() {
		return "VoteItem [id=" + id + ", title=" + title + ", description="
				+ description + ", vote=" + vote + ", answeres=" + answeres
				+ "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		VoteItem other = (VoteItem) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	private Long id;
	private String title;
	private String description;
	private Vote vote;
	private Set<Answer> answeres=new HashSet<Answer>();
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	@ManyToOne(cascade={CascadeType.MERGE})
	@JoinColumn(name="vote_id")
	public Vote getVote() {
		return vote;
	}

	public void setVote(Vote vote) {
		this.vote = vote;
	}
	

}
